package com.estun.backroundManagementService.modules.position.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estun.backroundManagementService.modules.position.mapper.DeviceMapper;
import com.estun.backroundManagementService.modules.position.model.Device;
import com.estun.backroundManagementService.modules.position.model.Position;
import com.estun.backroundManagementService.modules.position.service.DeviceService;
import com.estun.backroundManagementService.modules.position.service.PositionService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@AllArgsConstructor
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {

    private final PositionService positionService;

    @Override
    public String getDeviceCodeByStationId(String stationId) {
        Position position = positionService.getByStationId(stationId);
        List<Device> deviceList = list(new QueryWrapper<Device>().eq("position_id", position.getId()));
        if (deviceList.isEmpty()){
            return "A20234065932";
        }else {
            return deviceList.get(0).getCode();
        }
    }
}
